<?php
/**
 * 彩种
 * @author Administrator
 *
 */
namespace app\common\logic;
use think\Model;
use app\common\model\BetTing;
use think\Db;

class LotteryCategory extends Model
{
	protected $betting_logic;
	
	protected function initialize()
	{
		parent::initialize();
		$this->betting_logic = new BetTing();
	}
	/**
	 * 彩种查找
	 */
	public function LotteryForSettlement()
	{
		$where = array('cp_if_open'=>1);
		return $this->betting_logic->CaiZhongList($where);
	}
	/**
	 * 投注记录
	 * @param string $limit
	 */
	public function SettlementRecordList($tz_sql,$type='')
	{
	    $us_sql = input('get.us_sql') ? input('get.us_sql') : '';
	    $limit = input('limit')?input('limit'):20;
		//搜索
		$where = array();
		if(input('get.us_sql')){
			$where['a.username'] = ['LIKE',"%{$us_sql}%"];
		}
		if(input('get.qihao_sql')) {
			$where['qihao'] = input('get.qihao_sql');
		}
		if(input('get.sDate1') || input('get.sDate2')) {
			if(input('get.sDate1') && input('get.sDate1') && input('get.sDate1') != '' && input('get.sDate2') !='') {
				$star = strtotime(input('get.sDate1')." 00:00:00");
				$end = strtotime(input('get.sDate2')." 23:59:59");
				$where['a.tz_time'] = ['between',$star.','.$end];
			}
		}
		//条件判断
		
		if(empty($type)){
		    if(!input('get.czid')){
		        $where['a.id'] = ['>',0];
		    }else{
		        $where['a.czid'] = input('get.czid');
		    }
		}else{
		    if(!input('get.czid')){
    		    if(input('get.us_sql')){
    	            $where['a.id'] = ['>',0];
    	        }else{
    	            $where['a.id'] = ['>',0];
    	        }
		    }else{
		        $where['a.czid'] = input('get.czid');
		    }
		}
		/*if($tz_sql=="touzhu_list_no"){
			$where2=array('nbzh'=>1,'swzh'=>1);
			$array_username=Db::name('username')->where($where2)->column('username');
			$where['a.username']=['not in',$array_username];
		}*/
		
		$order = "a.tz_time DESC";
		$res = Db::name($tz_sql)->alias('a')->where($where)->value('SUM(tzje) as je');
		$zjje = Db::name($tz_sql)->alias('a')->where($where)->value('SUM(zjje) as je');
		$data = $this->betting_logic->SettlementRecordList($tz_sql, $where,$limit,$order);
		return array('data'=>$data?$data:[],'qjje'=>$res,'zjje'=>$zjje);
	}
	
}